package com.shugl.demo.controller;

import com.shugl.demo.entity.SysModule;
import com.shugl.demo.entity.SysVersion;
import com.shugl.demo.exception.ParamException;
import com.shugl.demo.mapper.SysModuleMapper;
import com.shugl.demo.mapper.SysVersionMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * create by shugl on 2020/5/22
 * @author admin
 */
@RestController
@RequestMapping("sys/sysModule")
@Api(tags = "系统模块")
@Transactional(rollbackFor = Exception.class)
public class SysModuleController {

    @Resource private SysModuleMapper sysModuleMapper;
    @Resource
    private SysVersionMapper sysVersionMapper;

    @Resource
    private PlatformTransactionManager platformTransactionManager;
    @Resource
    private TransactionDefinition transactionDefinition;



    @GetMapping(value = "queryAllModule")
    public Long queryAllModule(){
        Date start = new Date();
        sysModuleMapper.queryAllSysModuleVo();
        Date end = new Date();
        return end.getTime() - start.getTime();
    }
    @ApiOperation("hello")
    @GetMapping("hello")
    public void test() {
        TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
        SysModule sysModule = new SysModule();
        sysModule.setModuleName("312");
        sysModuleMapper.insert(sysModule);
        platformTransactionManager.rollback(transactionStatus);
//        throw new ParamException("参数未传");
    }


}
